/**
 * Created by wsx on 2016/11/1.
 */
$(function () {
    var pimgflag = false;
    var pnameflag = false;
    var phonorflag = false;
    var prankflag = false;
    var pinfoflag = false;
    $("#pname").blur(function () {
        if($(this).val() != ""){
            pnameflag = true;
        }
    });
    $("#phonor").blur(function () {
        if($(this).val() != ""){
            phonorflag = true;
        }
    });
    $("#prank").blur(function () {
        if($(this).val() != ""){
            prankflag = true;
        }
    });
    $("#pinfo").blur(function () {
        if($(this).val() != ""){
            pinfoflag = true;
        }
    });
    $('#pimg').change(function () {
        var filepath = $(this).val();
        var ext = filepath.substring(filepath.lastIndexOf("."), filepath.length).toUpperCase();
        if(ext != ".BMP" && ext != ".PNG" && ext != ".GIF" && ext != ".JPG" && ext != ".JPEG"){
            alert("图片限于bmp,png,gif,jpeg,jpg格式");
            $(this).val("");
            pimgflag = flase;
        }else{
            var filesize = document.getElementById("pimg").files[0].size/1024/1024;
            if(filesize > 2){
                alert("图片请小于5M");
                $(this).val("");
                pimgflag = flase;
            }
            pimgflag = true;
        }
    });
    $('#tijiao').click(function () {
        if(pimgflag && pnameflag && phonorflag && prankflag && pinfoflag){
            $.ajaxFileUpload({
                url: "/back/addproajax",
                secureuri: false,
                fileElementId: 'pimg',
                data: {
                    pname:$('#pname').val(),
                    phonor:$('#phonor').val(),
                    pinfo:$('#pinfo').val(),
                    prank:$('#prank').val()
                },
                dataType: "text",
                success: function (data) {
                    alert(data);
                }
            });
        }else{
            alert("信息填写不正确！");
        }
    });

});